var canReach = function(arr, start) {
    let map = {}
    arr.forEach((item, index) => {
        map[index] = false
    });
    map[start] = true
    let rslFlag = false

    function search(curIndex) {
        if (arr[curIndex] === 0) {
            rslFlag = true
            return
        }
        if (curIndex !== start && (map[curIndex] || rslFlag)) {
            return
        }
        map[curIndex] = true
        if (curIndex + arr[curIndex] < arr.length) {
            search(curIndex + arr[curIndex])
        }
        if (curIndex - arr[curIndex] >= 0) {
            search(curIndex - arr[curIndex])
        }
    }
    search(start)
    return rslFlag
};
console.log(canReach([3, 0, 2, 1, 2], 2))